package com.study.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class Encryption {
	/**
	 * 字符串加密
	 * @param str 原字符串
	 * @return
	 * @throws NoSuchAlgorithmException
	 */
	public static String  getMD5(String str) throws NoSuchAlgorithmException {
		MessageDigest mdDigest = MessageDigest.getInstance("MD5");
		BASE64Encoder base64Encoder = new BASE64Encoder();
		String nowStr = str;
		try {
			nowStr = base64Encoder.encode(mdDigest.digest(str.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace(); 
		}
		return nowStr; 
	}
}
